package attend.action.attend;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import exception.BaseException;
import attend.com.Session;

public class FileDownloadAction extends Session {
	
	private 	String 			basePath;
	private 	String 			fileName;
	private 	String 			contentType;
	private 	String 			contentDisposition;
	private 	InputStream		inputStream;
	private 	long			contentLength;
	
	public FileDownloadAction() {}
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	/**
	 * @since	2009/03/19
	 * @author Yang D
	 * @return	String
	 * @throws BaseException
	 * @exception BaseException
	 */
	public String execute() throws BaseException {
		
		//globalMessage.properties
		basePath			=	getText("path.download_base");
		fileName			=	getText("file.philsys_rule_provision_doc");
		
		String 	inputPath	=	basePath + "/" + fileName;
		File 	f			=	new File(inputPath);
		
		setContentLength(f.length());
		
		System.out.println(fileName + " <-----------------fileName!!!!!!!!!!!!!!!!!!!!!!");
		
		
		
		try {
			setContentDisposition("attatchment; filename=" + URLEncoder.encode(fileName , "UTF-8"));
			setInputStream(new FileInputStream(inputPath));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		return SUCCESS;
	}
	
	public String userMenualDownload() throws BaseException {
		
		//globalMessage.properties
		basePath			=	getText("path.download_base");
		fileName			=	getText("file.philsys_user_menual");//근태관리사용자매뉴얼ver2.0.ppt
		
		String 	inputPath	=	basePath + "/" + fileName;
		File 	f			=	new File(inputPath);
		
		setContentLength(f.length());
		
		System.out.println(fileName + " <-----------------fileName!!!!!!!!!!!!!!!!!!!!!!");
		
		
		
		try {
			setContentDisposition("attatchment; filename=" + URLEncoder.encode(fileName , "UTF-8"));
			setInputStream(new FileInputStream(inputPath));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
	
	/**
	 * <pre>
	 * 	노동부 최저임금 고시 2009.12.31까지
	 * </pre>
	 * @return
	 * @throws BaseException
	 */
	public String noticeMinimumWage_p() throws BaseException {
		//
		
		return SUCCESS;
	}
	
	/*******************************************************************************************/
	
	public String getBasePath() {
		return basePath;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getContentDisposition() {
		return contentDisposition;
	}

	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public long getContentLength() {
		return contentLength;
	}

	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}
}
